home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 13.4 KB | 469 lines | [TEXT/MPS ] |
- // UMacAppUtilities.h
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
-
- #ifndef __UMACAPPUTILITIES__
- #define __UMACAPPUTILITIES__
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __PASCALSTRING__
- #include "PascalString.h"
- #endif
-
- #ifndef __TOOLBOX__
- #include "Toolbox.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- // Toolbox
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- //----------------------------------------------------------------------------------------
- // Forward declarations
- //----------------------------------------------------------------------------------------
- class TStream;
- class TView;
-
- //----------------------------------------------------------------------------------------
- // Global constants declarations. Build options.
- //----------------------------------------------------------------------------------------
-
- // constants passed in as flags to MATextBox()
- enum { kDontPreferOutline, kPreferOutline };
-
- //----------------------------------------------------------------------------------------
- // Some useful struct(s)
- //----------------------------------------------------------------------------------------
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- struct MATextStyle
- {
- Style tsFace; // character Style
- char filler; // tsFace is unpacked byte
- short tsSize; // size in points
- CRGBColor tsColor; // absolute (RGB) color
- CStr255 tsFont; // font (family) number
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
- typedef MATextStyle *MATextStylePtr, **MATextStyleHandle;
-
-
- //----------------------------------------------------------------------------------------
- // Global variable declarations.
- //----------------------------------------------------------------------------------------
-
- #if qDebugMsg
- extern const CStr15 gBoolString[2];
- #endif
- extern Boolean gUDialogInitialized;
- extern Boolean gUGridViewInitialized;
- extern Boolean gUPrintingInitialized;
- extern Boolean gUTEViewInitialized;
- extern TEHandle gMATextBoxTE;
- extern WordBreakUPP gTEDefaultWordBreak;
- extern const VHSelect gOrthogonal[2];
- extern const CRect gZeroRect;
- extern const CPoint gZeroPt;
- extern const VPoint gZeroVPt;
- extern const VRect gZeroVRect;
- extern const CPoint kBestSystemLocation; // use when system calls take -1,-1 for best window locations
- extern const CStr2 gEmptyString;
- extern const CRGBColor gRGBBlack;
- extern const CRGBColor gRGBWhite;
- extern const CRGBColor gRGBRed;
- extern const CRGBColor gRGBGreen;
- extern const CRGBColor gRGBBlue;
-
- //------------------------------------------------------------------------------------
- // CWhileOutlinePreferred: A simple class for setting/restoring outline preferred.
- //------------------------------------------------------------------------------------
-
- class CWhileOutlinePreferred
- {
- Boolean fPreferOutline;
- Boolean fOutlinePreferredChanged;
-
- public:
- // Constructor/destructor
- CWhileOutlinePreferred(Boolean preferOutline);
- ~CWhileOutlinePreferred();
- };
-
- //----------------------------------------------------------------------------------------
- // CStringListRsrc: A simple class for managing and accessing strings in STR# resources.
- //
- // Limitations: this class has no notion of which resource file to be used for accessing
- // the strings from the CString list resource. This could be added as an enhancement.
- //----------------------------------------------------------------------------------------
-
- class CStringListRsrc
- {
- public:
- //----------------------------------------------------------------------------------------
- // class-scoped constants
- //----------------------------------------------------------------------------------------
- enum { kDontAddString, kAddString };
-
- //----------------------------------------------------------------------------------------
- // constructors
- //----------------------------------------------------------------------------------------
- inline CStringListRsrc(short strListID, const CStr255& strListRsrcName) :
- fStrListID(strListID),
- fStrListRsrcName(strListRsrcName)
- {}
- // constructor
-
- inline CStringListRsrc(short strListID) :
- fStrListID(strListID)
- { }
- // constructor
-
- //----------------------------------------------------------------------------------------
- // accessors
- //----------------------------------------------------------------------------------------
- short AppendString(const CStr255& theString);
- // append theString to the STR# resource whose id is fStrListID and return its index
-
- void ClearAll();
- // clears all strings in the STR# resource
-
- short CountStrings() const;
- // returns the number of strings in the STR# resource whose id is fStrListID
-
- short FindString(const CStr255& theString, Boolean addString = kDontAddString);
- // find theString in the STR# resource whose id is fStrListID and return its index
- // if theString is not found in the STR# resource, add it if addString is kAddString
-
- void GetListName(CStr255& itsName);
- // Returns the name of the STR# list either from its field or if that is empty
- // from the actual resource
-
- void GetString(short index, CStr255& theString) const;
- // return in theString the "index" CString in the STR# resource whose id is fStrListID
-
- void RemoveAt(short index);
- // removes the CString at the specified index.
-
- void ReplaceAt(const CStr255& theString, short index);
- // replace the CString at "index" with "theString"
-
- //----------------------------------------------------------------------------------------
- // data members
- //----------------------------------------------------------------------------------------
- protected:
- CStr255 fStrListRsrcName; // The name of the STR# rsrc, this is
- // only used when adding the STR# rsrc.
- ResNumber fStrListID; // The ID of the STR# rsrc.
- };
-
-
- //----------------------------------------------------------------------------------------
- // CWMgrIterator: A simple iterator for window lists.
- //----------------------------------------------------------------------------------------
-
- class CWMgrIterator
- {
- private:
- WindowRef fCurrentWindow;
-
- protected:
- Boolean fIterateForward;
-
- public:
- CWMgrIterator(Boolean itsForward = TRUE);
-
- inline Boolean More() // override
- { return (fCurrentWindow != NULL); }
- // Returns true if there are more elements to iterate over
-
- void Reset(); // override
- // Resets the iterator to begin again
-
- inline WindowRef CurrentWMgrWindow()
- { return fCurrentWindow; } // Always return the current window
-
- // returns the current window
-
- WindowRef FirstWMgrWindow();
- // Resets the iterator to begin again and returns the first window in the window list
-
- WindowRef NextWMgrWindow();
- // increments and then returns the window in the window list
-
- protected:
- void Advance(); // override
- // Advances the iteration
-
- WindowRef NextWindow(WindowRef aWindow);
- // returns the next window in the window list, excluding gWorkPort
-
- WindowRef PreviousWindow(WindowRef aWindow);
- // returns the previous window in the window list, excluding gWorkPort
-
- WindowRef FirstWindow();
- // returns the first window in the window list, excluding gWorkPort
-
- WindowRef LastWindow();
- // returns the last window in the window list, excluding gWorkPort
-
- };
-
-
- //----------------------------------------------------------------------------------------
- // Global function declarations that needs to always be compiled for 68000.
- //----------------------------------------------------------------------------------------
-
- void CenterRectOnScreen(CRect& aRect,
- Boolean horizontally,
- Boolean vertically,
- Boolean forDialog);
-
- void ConcatNumber(const CStr255& aString,
- long aNumber,
- CStr255& theResult);
-
- void PullApplicationToFront();
-
- inline void SetRGBColor(CRGBColor& RGB,
- short aRed,
- short aGreen,
- short aBlue)
- { RGB.red = aRed; RGB.green = aGreen; RGB.blue = aBlue; }
-
- OSErr MAInteractWithUser(long timeOutInTicks, NMRecPtr nmReqPtr, AEIdleUPP idleProc);
-
- OSErr MAInteractWithUser();
-
- OSErr MAInteractWithUserNoIdleProc();
-
- //----------------------------------------------------------------------------------------
- // Global function declarations
- //----------------------------------------------------------------------------------------
-
- #if qNeedsSystem7_5
- inline short MACharacterByteType(Ptr textBuf, short textOffset, ScriptCode script)
- { return CharacterByteType(textBuf, textOffset, script); }
- #else
- short MACharacterByteType(Ptr textBuf, short textOffset, ScriptCode script);
- #endif
-
- #if qNeedsSystem7_5
- inline short MACharacterType(Ptr textBuf, short textOffset, ScriptCode script)
- { return CharacterType(textBuf, textOffset, script); }
- #else
- short MACharacterType(Ptr textBuf, short textOffset, ScriptCode script);
- #endif
-
- Boolean CompareMultiByteChars(const CStr31& first,
- const CStr31& second,
- Boolean caseSens);
- // Special case single byte characters and allow case insensitive comparisons
-
- inline short CompareStrings(const CStr255& first, const CStr255& second)
- { return ::CompareString(first, second, NULL); }
-
- inline void CopyStr255(const CStr255& fmStr, Ptr toAddr)
- { fmStr.CopyTo((unsigned char*)toAddr); }
-
- WindowRef FindWindowBefore(WindowRef theWindow);
-
- void DefaultSize(short& theSize);
-
- PicHandle DisposeIfPicHandle(PicHandle aPicHandle);
-
- RgnHandle DisposeIfRgnHandle(RgnHandle aRgnHandle);
-
- SectionHandle DisposeIfSectionHandle(SectionHandle aSectionHandle);
-
- short GetActualJustification(short justification);
-
- void GetDeskTopRegion(RgnHandle deskTopRgn);
-
- void ShowGlobalRegion(RgnHandle globalRegion);
-
- void ShowViewRegion(TView *theView, RgnHandle viewRegion);
-
- short GetFontNum(const CStr255& fontName);
-
- CRGBColor GetIfColor();
- inline void GetIfColor(CRGBColor& aColor)
- { aColor = GetIfColor(); }
-
- CRGBColor GetIfBkColor();
- inline void GetIfBkColor(CRGBColor& aColor)
- { aColor = GetIfBkColor(); }
-
- void GetPortTextStyle(TextStyle& theTextStyle);
-
- void MAGetTextStyle(ResNumber rsrcID, TextStyle& theTextStyle);
- // Given the rsrcID of a 'TxSt' resource, this function creates and
- // returns in theTextStyle the corresponding TextStyle record.
-
- void GetPortFontInfo(short fontNum, CStr255& fontName, short& fontSize);
-
- long GetRandom(long rangeStart, long rangeEnd);
-
- Boolean IsColorPort(GrafPtr port);
-
- inline short GetWindowVariant(WindowRef theWindow)
- { return GetWVariant(theWindow); }
- // For MacApp 3.0 app's, _GetWVariant is *always* available.
-
- inline short LengthRect(const CRect& r, VHSelect vhs)
- { return r.GetLength(vhs); }
-
- VHSelect LongerSide(CRect& r);
-
- VHSelect LongerVSide(VRect& r);
-
- void LIntToHex(long decNumber, CStr31& hexNumber, short noOfDigits);
-
- short MAGetFontInfo(FontInfo& theFontInfo);
-
- void MATextBox(Ptr text,
- long itsLength,
- const CRect& box,
- short itsJust,
- Boolean autoWrap,
- ProcPtr wordBreak,
- Boolean eraseFirst,
- Boolean spaceForCaret,
- Boolean preferOutline = kDontPreferOutline);
-
- void MADrawString(const CStr255& s,
- const CRect& box,
- short justification,
- Boolean preferOutline = kDontPreferOutline);
-
- void NumberToHex(long theNumber,
- CStr255& hexString,
- short hexDigits);
-
- Boolean IsThisKeyDown(const short theKey);
- // Returns TRUE if the specified key is currently depressed. (Pushed down, not unhappy!)
-
- Boolean IsCapsLockKeyDown();
-
- Boolean IsCommandKeyDown();
-
- Boolean IsControlKeyDown();
-
- Boolean IsOptionKeyDown();
-
- Boolean IsShiftKeyDown();
-
- long PinOnRect(const CRect& theRect, CPoint thePt);
-
- void PinOnVRect(const VRect& theRect, const VPoint& thePt, VPoint& thePin);
-
- void PointerToHex(long theNumber, CStr31& hexString, short hexDigits);
-
- inline Boolean RectsNest(const CRect& outer, const CRect& inner)
- { return outer.Contains(inner); }
-
- inline Boolean VRectsNest(const VRect& outer, const VRect& inner)
- { return outer.Contains(inner); }
-
- long RoundUp(long aNumber, short aModulus);
-
- short SetKeyScript(short newKeyScript);
-
- void SetIfColor(const CRGBColor& aColor);
-
- void SetIfBkColor(const CRGBColor& aColor);
-
- void SetPortTextStyle(const TextStyle& theTextStyle);
-
- void SetTextStyle(TextStyle& theTextStyle,
- short theFont,
- /* Style */
- short theStyle,
- short theSize,
- const CRGBColor& theColor);
-
- void UseSelectionColor();
-
- void UseROMMap(Boolean resLoad);
-
- long NumBlocks(long numBytes, long blkSize);
-
- #if qDebug
- Boolean CanReadLn();
- #else
- inline Boolean CanReadLn()
- { return FALSE; }
- #endif
-
- #if qDebug
- Boolean CanWriteLn();
- #else
- inline Boolean CanWriteLn()
- { return FALSE; }
- #endif
-
- inline void CopyPat(const Pattern& pat, Pattern& toPat)
- { toPat = pat; } // Patterns are structures now
-
- void XorPat(const Pattern& patA, const Pattern& patB, Pattern& toPat);
-
- void RotatePat(Pattern& aPattern);
-
- Handle StreamToHandle(TStream* theStream);
-
- //----------------------------------------------------------------------------------------
- // System configuration.
- //----------------------------------------------------------------------------------------
-
- #if qOldConfigurationFlags
-
- // The Configuration structure and gConfiguration are obsolete.
- // Use the configuration functions in UMacAppUtilities instead.
- // For example, instead of gConfiguration.hasSpeechManager,
- // use HasSpeechManager().
-
- extern Configuration gConfiguration;
- #endif
-
- #endif // __UMACAPPUTILITIES__
-